package com.kaifamiao.coordinate;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BocTest {

    public static void main(String[] args) {

        BocAccount account = new BocAccount( "阿芳", 1000, 500 );

        ExecutorService es = Executors.newFixedThreadPool(2);

        Callable<?> depositTask = () -> {
            for (int i = 0; i < 3; i++) {
                account.deposit(800); // 调用同步方法
                Thread.yield();
            }
            return null;
        };

        Runnable withdrawTask = () -> {
            for (int i = 0; i < 3; i++) {
                account.withdraw(800); // 调用同步方法
                Thread.yield();
            }
        };

        es.submit(depositTask);
        es.submit(withdrawTask);

        es.shutdown();

    }

}
